import unittest
from time import sleep

from parameterized import parameterized

from page.w_warehouse_commodity_management_page import WarehousePage1


class TestWarehouse1(unittest.TestCase):
    warehouse1 = None

    @classmethod
    def setUpClass(cls) -> None:
        cls.warehouse1 = WarehousePage1()
        cls.warehouse1.login_admin()

    @classmethod
    def tearDownClass(cls) -> None:
        sleep(3)
        cls.warehouse1.driver.quit()

    def test_add_commodity(self):
        msg = self.warehouse1.add_commodity()
        print('预期结果为：', '添加成功', '实际结果为：', msg)
        try:
            self.assertEqual(msg, '添加成功')
        except:
            self.warehouse1.get_image('w')
            raise

    def test_delete_commodity(self):
        msg = self.warehouse1.delete_commodity()
        print('预期结果为：', '删除成功', '实际结果为：', msg)
        try:
            self.assertEqual(msg, '删除成功')
        except:
            self.warehouse1.get_image('w')
            raise

    @parameterized.expand('苹果')
    def test_reset_search_commodity(self, commodity):
        self.warehouse1.reset_search_commodity(commodity)

    @parameterized.expand('100')
    def test_sidebar_commodity(self, inventory):
        msg = self.warehouse1.sidebar_commodity(inventory)
        print('预期结果为：', '删除成功', '实际结果为：', msg)
        try:
            self.assertEqual(msg, '删除成功')
        except:
            self.warehouse1.get_image('w')
            raise
